function y = nan2lim(x, l)

  global lim ;
  if (nargin < 2)
     if ( isempty(lim) )
	error("lim undefined.\n") ;
     endif
     l = lim ;
  endif 

  [nr nc] = size(x) ;

  if isscalar(l)
     l = repmat(l, 1, nc) ;
  endif 
  l = repmat(l, nr, 1) ;

  y = x ;
  ind = find(isnan(x)) ;
  y(ind) = l(ind) ;

endfunction
